package com.wxmsg;

import com.common.Constant;
import com.soecode.wxtools.api.IService;
import com.soecode.wxtools.api.WxMessageHandler;
import com.soecode.wxtools.bean.WxXmlMessage;
import com.soecode.wxtools.bean.WxXmlOutMessage;
import com.soecode.wxtools.exception.WxErrorException;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Map;
import java.util.Set;

/**
 * Created by lzb on 2018/5/11.
 */
public class AdminHandle implements WxMessageHandler{

    private RedisTemplate redisTemplate = (RedisTemplate) Constant.ctx.getBean("redisTemplate");

    @Override
    public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map<String, Object> context, IService iService) throws WxErrorException {


        String[] cmd=wxMessage.getContent().split(" ");
        String content="";



        switch(cmd[1]){
            case "dm"://删除菜单
                Constant.iService.deleteMenu();
                content="删除菜单完成.";
                break;
            case "wladd":
                redisTemplate.opsForSet().add(wxMessage.getFromUserName(),cmd[2]);
                content="涡轮添加完成.";
                break;
            case "wldel":
                redisTemplate.opsForSet().remove(wxMessage.getFromUserName(),cmd[2]);
                content="涡轮删除完成.";
                break;
            case "wlbuy":
                redisTemplate.opsForSet().add(wxMessage.getFromUserName()+"_BUY",cmd[2]);
                content="涡轮标记完成.";
                break;
            case "wldrop":
                redisTemplate.opsForSet().remove(wxMessage.getFromUserName()+"_BUY",cmd[2]);
                content="涡轮删除标记完成.";
                break;
            default:
                content="无法识别的管理指令.";
                break;
        }

        WxXmlOutMessage xmlOutMsg = WxXmlOutMessage.TEXT().content(content).toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName()).build();
        return xmlOutMsg;
    }
}
